﻿using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sovacode.RubiksCube.Common.Base;
using Sovacode.RubiksCube.Common.Command;
using Sovacode.RubiksCube.Common.Managers.Command;
using Sovacode.RubiksCube.Common.Managers.Validation;
using Sovacode.RubiksCube.Common.Service;
using Sovacode.RubiksCube.Common.Service.Linked;
using Sovacode.RubiksCube.Common.ViewModel;

namespace Sovacode.RubiksCube.Common.Tests.ViewModelCommon
{
    [TestClass]
    public class CommonViewModelTopTests
    {
        [TestMethod]
        public void EmptyViewModel()
        {
            var viewModelTop = new ViewModelTop();

            Assert.IsTrue(viewModelTop.InvalidCommandsCount == 0);
            Assert.IsTrue(viewModelTop.InvalidSettingsCount == 0);
            Assert.IsTrue(viewModelTop.InvalidValidatorsCount == 0);
            Assert.IsTrue(viewModelTop.CommandsCount == 0);
            Assert.IsTrue(viewModelTop.SettingsCount == 0);
            Assert.IsTrue(viewModelTop.ValidCommandsCount == 0);
            Assert.IsTrue(viewModelTop.ValidSettingsCount == 0);
            Assert.IsTrue(viewModelTop.ValidValidatorsCount == 0);
            Assert.IsTrue(viewModelTop.ValidatorsCount == 0);

            Assert.IsNotNull(viewModelTop.SettingsManager);
            Assert.IsNotNull(viewModelTop.ValidationManager);
            Assert.IsNotNull(viewModelTop.CommandManager);
            Assert.IsNotNull(viewModelTop.WindowService);

            Assert.IsNotNull(viewModelTop.InvalidCommands);
            Assert.IsNotNull(viewModelTop.InvalidSettings);
            Assert.IsNotNull(viewModelTop.InvalidValidators);
            
            Assert.IsNotNull(viewModelTop.ValidCommands);
            Assert.IsNotNull(viewModelTop.ValidSettings);
            Assert.IsNotNull(viewModelTop.ValidValidators);

            Assert.IsNotNull(viewModelTop.AllCommands);
            Assert.IsNotNull(viewModelTop.AllSettings);
            Assert.IsNotNull(viewModelTop.AllValidators);


            Assert.IsTrue(viewModelTop.IsValid);
        }

        [TestMethod]
        public void MustExposes()
        {
            var viewModelTop = new ViewModelTop();

            Assert.IsInstanceOfType(viewModelTop, typeof(INotifyValidatedObject));
            Assert.IsInstanceOfType(viewModelTop, typeof(INotifyPropertyChanged));
            Assert.IsInstanceOfType(viewModelTop, typeof(INotifyValidatedObject));
            Assert.IsInstanceOfType(viewModelTop, typeof(IViewModelTop));
            Assert.IsInstanceOfType(viewModelTop, typeof(IValidationRegistrar));
            Assert.IsInstanceOfType(viewModelTop, typeof(ICommandRegistrar));
            Assert.IsInstanceOfType(viewModelTop, typeof(IShowWindow));
            Assert.IsInstanceOfType(viewModelTop, typeof(NotifyValidatedObject));
            Assert.IsNotInstanceOfType(viewModelTop, typeof(IWindowService));
            Assert.IsNotInstanceOfType(viewModelTop, typeof(ILinkedWindowService));
        }

        [TestMethod]
        public void RegisterDefaultCommands()
        {
            var viewModelTop = new ViewModelTop();

            var defCommand = viewModelTop["LoadSettings"] as ICustomCommand;

            Assert.IsNotNull(defCommand);
            Assert.IsFalse(defCommand.Type == CommandType.Error);
            Assert.IsTrue(defCommand.Type == CommandType.Normal);

            Assert.IsTrue(viewModelTop.CommandsCount == viewModelTop.ValidCommandsCount);
            Assert.IsTrue(viewModelTop.ValidCommandsCount > 0);
        }
    }
}
